Skip to content

feat: print optimizer param groups when verbose - #1149

Merged
githubnemo merged 3 commits into
skorch-dev:masterfrom
aiedwardyi:feat/print-param-groups
Aug 3, 2026
Merged

feat: print optimizer param groups when verbose#1149
githubnemo merged 3 commits into
skorch-dev:masterfrom
aiedwardyi:feat/print-param-groups

Conversation

@aiedwardyi

@aiedwardyi aiedwardyi commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Prints which module parameters match each optimizer param group when verbose is set, both at init and on set_params. Fixes #291.

Review fixes applied (8eeac24)

  • Added tests for no / multiple param groups and duplicate-print guards.
  • Reverted the unnecessary optimizer local in optimizer_setter.
  • format_param_group_msg now reports params not among the module's learnable params instead of hiding them.
  • Gated set_params printing to a specific param group so global sets (e.g. optimizer__lr) stay quiet.

Review fixes applied (1608a15)

  • Truncate the verbose message to MAX_PARAM_GROUP_MSG_LEN (200 chars).
  • Combined the verbose print tests into one parametrized test that runs a short fit to guard against repeated messages during training.

@githubnemo githubnemo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on :)

The changes look good and nice to see tests from the start. I've made some comments.

Comment thread skorch/tests/test_net.py
Comment thread skorch/setter.py Outdated
Comment thread skorch/setter.py Outdated
- handle empty param_names in format_param_group_msg (unmapped params)
- gate set_params printing to a specific param group, not global sets
- revert unnecessary optimizer local; add no/multi-group + edge tests
@aiedwardyi

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @githubnemo! Addressed all three:

  • Tests - added no-param-groups and >1-group cases, plus count() assertions so duplicate prints are caught.
  • Revert - inlined getattr(net, optimizer_attr) back in optimizer_setter.
  • Unmapped params - format_param_group_msg now surfaces them explicitly instead of hiding them.

While adding the tests I also noticed set_params printed on global optimizer sets (e.g. optimizer__lr), which broke the reinitialization-message tests and would be noisy mid-training - I gated printing to a specific param group, matching #291's intent. All setter and param-group tests pass locally.

@githubnemo githubnemo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, they look reasonable!

Two more comments but otherwise LGTM

Comment thread skorch/setter.py Outdated
Comment thread skorch/tests/test_net.py Outdated

@githubnemo githubnemo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks :)

@githubnemo
githubnemo merged commit 2b54e3a into skorch-dev:master Aug 3, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Print param groups after initialization

2 participants